#include <iostream>
using namespace std;

void reverse(int i,int j,char arr[])
{
	while(i<j)
	{
		char temp = arr[i];
		arr[i] = arr[j];
		arr[j] = temp;
		++i;
		--j;
	}
}

void reverseWordsInSentence(char arr[],int length)
{
	if(arr == nullptr || length <= 0)
		return;
	reverse(0,length-1,arr);
	int begin = 0;
	for(int idx = 0 ; idx < length ; ++idx)
	{
		if(arr[idx] == ' ')
		{
			reverse(begin,idx-1,arr);
			begin = idx+1;
		}
	}
	reverse(begin,length-1,arr);
}

int main()
{
	char arr[] = "merry christmas am a student.";
	char arr1[] = "hello";
	char arr2[] = "";
	char arr3[] = "    ";
	cout<<arr<<endl;
	reverseWordsInSentence(arr,29);
	reverseWordsInSentence(arr1,5);
	reverseWordsInSentence(arr2,0);
	reverseWordsInSentence(arr3,4);
	cout<<arr2<<endl;
	cout<<arr3<<endl;
	cout<<arr1<<endl;
	cout<<arr<<endl;
	return 0;
}